extends CharacterBody3D

signal squashed

@onready var animation_player = $AnimationPlayer

@export var min_speed = 10
@export var max_speed = 18


#func _init():
	#print("_init enter.")
#func _enter_tree():
	#print("_enter_tree enter.")
#func _ready():
	#print("_ready enter.")

func _physics_process(delta):
	move_and_slide()

func initalize(start_position, player_position):
	#print("initalize enter.")
	var pos1 = start_position;
	pos1.y = 0;
	var pos2 = player_position;
	pos2.y = 0;
	
	look_at_from_position(pos1, pos2, Vector3.UP)
	rotate_y(randf_range(-PI / 4, PI / 4))
	
	var random_speed = randi_range(min_speed, max_speed)
	velocity = Vector3.FORWARD * random_speed
	velocity = velocity.rotated(Vector3.UP, rotation.y)
	
	#animation_player.speed_scale = random_speed / min_speed
	$AnimationPlayer.speed_scale = random_speed / min_speed

func _on_visible_on_screen_notifier_3d_screen_exited():
	queue_free()

func squash():
	squashed.emit()
	queue_free()
